package fhv.at.imageprocessing.editors;

import javax.media.jai.KernelJAI;

public class LaplaceKernelEditor extends KernelEditor {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public LaplaceKernelEditor() {
		super();
		init();
	}

	private void init() {
		addPreDefinedItem("Laplace 1");
		addPreDefinedItem("Laplace 2");
		addPreDefinedItem("Laplace 3");
		addPreDefinedItem("Laplace 4");

	}

	@Override
	protected void setPreDefinedKernel(String kernelName) {

		if (kernelName.equals("Laplace 1")) {
			setKernelLaplace1();
		} else if (kernelName.equals("Laplace 2")) {
			setKernelLaplace2();
		} else if (kernelName.equals("Laplace 3")) {
			setKernelLaplace3();
		} else if (kernelName.equals("Laplace 4")) {
			setKernelLaplace4();
		} else {
			setKernelDefault();
		}
		pcs.firePropertyChange("", null, null);
	}

	private void setKernelLaplace1() {
		float[] kernelData = { 0.0F, -1.0F, 0.0F, -1.0F, 4.0F, -1.0F, 0.0F,
				-1.0F, 0.0F, };
		kernel = new KernelJAI(3, 3, kernelData);
		setValue(kernel);
	}

	private void setKernelLaplace2() {
		float[] kernelData = { 0.0F, -1.0F, -1.0F, -1.0F, 8.0F, -1.0F, -1.0F,
				-1.0F, 0.0F, };
		kernel = new KernelJAI(3, 3, kernelData);
		setValue(kernel);
	}

	private void setKernelLaplace3() {
		float[] kernelData = { 1.0F, -2.0F, 1.0F, -2.0F, 4.0F, -2.0F, 1.0F,
				-2.0F, 1.0F, };
		kernel = new KernelJAI(3, 3, kernelData);
		setValue(kernel);
	}

	private void setKernelLaplace4() {
		float[] kernelData = { -1.0F, -2.0F, -1.0F, -2.0F, 12.0F, -2.0F, -1.0F,
				-2.0F, -1.0F, };
		kernel = new KernelJAI(3, 3, kernelData);
		setValue(kernel);
	}
}
